using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    Vector3 distance = new Vector3(0, 8, -18);
    new Camera camera;
    Vector3 offset = new Vector3(0, 5, 0);
    int speed = 3;
    void Start()
    {
        camera = Camera.main;
        camera.transform.position = transform.position - 30 * transform.forward + 10 * Vector3.up;

    }

    // Update is called once per frame
    void LateUpdate()
    {
        Vector3 pos = transform.position;
        Vector3 targetPos = pos + transform.forward * distance.z;
        targetPos.y += distance.y;
        Vector3 cameraPos = camera.transform.position;
        cameraPos = Vector3.MoveTowards(cameraPos, targetPos, Time.deltaTime * speed);
        camera.transform.position = cameraPos;
        camera.transform.LookAt(pos + offset);
    }
}
